package cn.com.callback

import groovy.json.*;
import groovy.swing.impl.DefaultAction
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.crypto.Cipher
import javax.crypto.SecretKey
import javax.crypto.spec.SecretKeySpec
import javax.servlet.RequestDispatcher;
import cn.com.callback.CallBackInvoke
import cn.com.callback.ServiceBackInvoke
import cn.com.elite.EliteBean;
import cn.com.elite.Util;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.ParseException
import java.text.SimpleDateFormat;
import java.time.Instant

import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

import cn.com.kh.KHUtil;
import cn.com.kh.hst.ThreeDesUtil;
import cn.com.kh.getProperty;
import com.huasheng.passwordencrypt.DecryptUtil


/**
 *
 * @Title: aipHSTCustRegisterinfo
 * @Description:华盛证券 服务顾问 按照用户的华盛号查询客户注册后的一些信息 --内部接口
 * @author: cheih
 * @date 2022-04-19 22:00:00
 *
 */

public class aipHSTCustRegisterinfo implements ServiceBackInvoke {
	private static final Log log = LogFactory.getLog(aipHSTCustRegisterinfo.class);

	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

		response.setCharacterEncoding("UTF-8");

		String getMethod = request.getMethod();
		log.debug("getMethod:" + getMethod);

		String inData = "";
		String outData = "";
		String dataSourceID = "dataSource";

		BufferedReader iny = null;
		if (getMethod.equals("GET")) {
			inData = request.getParameter("data");
			log.debug("原始Get请求参数:" + inData);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				inData += line;
			}
			log.debug("原始Post请求参数:" + inData);
		}

		try {

			long startTime = System.currentTimeMillis();
			String reJson = null;
			long endTime = 0;

			// 调用处理信息
			JSONObject inObject = new JSONObject(inData);
			log.debug("处理前的Json：" + inObject.toString());
			def token = GetJV(inObject, "token");//token
			def hsNo = GetJV(inObject, "hsNo");//华盛号
			def remoteAddr = ThreeDesUtil.getIpAddr(request);//坐席ip

			if(hsNo==""||token=="") {
				log.debug("参数不能都为空");
				reJson = "{\"result\":\"-1\",\"message\":\"接口入参为空\"}";
				return reJson;
			}
			log.debug("解析信息-" + "hsNo: " + hsNo+ "token: " + token);

			def customer_guid,objective_guid="";
			String getcustSQL = "select c.customer_guid,o.objective_guid from customer c left join objective o on c.customer_guid=o.customer_guid and o.map_id='MY48ZX' where 1=1  and c.customer_id='" + hsNo + "'";
			List getcustList = eliteBean.chaxun_sql(getcustSQL, "dataSource");
			log.debug("getcustList:" + getcustList.toString());

			//鉴权变量
			String appid = getProperty.get("appid");
			String appsecret = getProperty.get("appsecret");

			//sign加密前后
			String signfront = "";
			String signafter = "";

			String sign_time=Instant.now().getEpochSecond();
			log.debug("解析信息-" + "sign_time: " + sign_time);

			HashMap<String, String> paramHashMap = new HashMap<String, String>();
			paramHashMap.put("token", token);
			paramHashMap.put("sign_time", sign_time);
			if(hsNo!=''&&hsNo!=null&&hsNo!="undefined") {
				paramHashMap.put("hsNo", hsNo);
			}

			log.debug("paramHashMap：" + paramHashMap);
			//自然排序 升序参数
			signfront= ThreeDesUtil.sortMap(paramHashMap,appid,appsecret);
			log.debug("sign加密MD5前：" + signfront);
			signafter = Util.getMD5Str(signfront);
			log.debug("sign加密MD5后：" + signafter);

			//拼接接口入参
			paramHashMap.put("client_key", appid);
			paramHashMap.put("sign", signafter);

			String injson=ThreeDesUtil.SplicingMap(paramHashMap,"&");
			log.debug("injson:" + injson);

			if(getcustList.size()>0){
				Map getcustMap = getcustList.get(0);
				customer_guid = getcustMap.get("customer_guid");
				objective_guid = getcustMap.get("objective_guid");
				log.debug("当前客户-" + "customer_guid: " + customer_guid+ "objective_guid: " + objective_guid);

				//reJson = "{\"result\":\"-1\",\"message\":\"当前客户已存在\"}";
				//return reJson;
				//更新 customer 无objective elitetask 任务
				if(objective_guid==null){
					outData =getcust2(eliteBean,injson,customer_guid);
				}else{//更新 customer  有objective elitetask 任务的情况
					outData =getcust1(eliteBean,injson,customer_guid);
				}
			}else {
				//新增
				outData = getcust(eliteBean, injson, dataSourceID);
			}
		} catch (Exception e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			outData = "{\"result\":\"-1\",\"message\":\"接口查询失败(" + e.getMessage() + ")\",\"data\":[]}";
		}
		log.debug("处理完成返回结果:" + outData);

		return outData;
	}

	//Loginin
	public static String getcust(EliteBean eliteBean , String injson, String dataSourceID) {

		long startTime = System.currentTimeMillis();
		log.debug("处理开始时间:" + startTime);

		long endTime = System.currentTimeMillis();

		String reJson = null;
		try {

			String doURL = getProperty.get("HSTURL");
			doURL = doURL+"/ae/query-register-info";
			log.debug("doURL:" + doURL);

			Map<String, String> headMap = new HashMap<String, String>();
			headMap.put("Content-Type", "application/x-www-form-urlencoded");
			def getResult = Util.doHttpPostUseHead(doURL, injson, "UTF-8", 10000, 0, headMap);
			log.debug("getResult:" + getResult);

			//解析SSO返回信息
			JSONObject jsonObject = new JSONObject(getResult);
			String code = GetJV(jsonObject, "code");
			String result = GetJV(jsonObject, "result");

			JSONObject dataObject;
			log.debug("code:" + code);
			if(code == "00000") {
				dataObject = new JSONObject(result);
				String registerstatus = GetJV(dataObject, "registerstatus");//1已开户 2（注册） 3（暂存） 4（审核中）
				String customerid = GetJV(dataObject, "customerid");//华盛号
				String customername = GetJV(dataObject, "customername");//姓名
				String phone = GetJV(dataObject, "phone");//手机号
				String register = GetJV(dataObject, "register");//注册渠道
				String register_id = GetJV(dataObject, "register_id");//注册渠道ID
				String registertime = GetJV(dataObject, "registertime");//注册时间
				String stashtime = GetJV(dataObject, "stashtime");//暂存时间
				String audittime = GetJV(dataObject, "audittime");//审核时间
				String invitertype = GetJV(dataObject, "invitertype");//邀请类型
				String inviterhstno = GetJV(dataObject, "inviterhstno");//邀请人华盛号
				String invitername = GetJV(dataObject, "invitername");//邀请人姓名

				//手机号脱敏
				String phone_enc =  DecryptUtil.encrypt(phone) ;

				if(registertime!=""){
					registertime="'"+registertime+"'";
				}else{
					registertime=null;
				}
				if(stashtime!=""){
					stashtime="'"+stashtime+"'";
				}else{
					stashtime=null;
				}
				if(audittime!=""){
					audittime="'"+audittime+"'";
				}else{
					audittime=null;
				}

				// 生成相关ID
				String Temp_Guid = KHUtil.getRandomString(31).toUpperCase();
				String Customer_Guid = "CUST_" + Temp_Guid;
				String Objective_Guid = "OBJE_" + Temp_Guid;
				String EliteTask_Guid = "TASK_" + Temp_Guid;
				log.debug("Customer_Guid:    "+Customer_Guid);

				String[] custTaskDealSQL = new String[3];
				custTaskDealSQL[0] = "Insert Into Customer" +
						"  (Customer_Guid," +
						"   Customer_Id," +
						"   stringfield9," +
						"   Customername," +
						"   Mobile," +
						"   Mobile_enc," +
						"   Stringfield13," +
						"   sq_9," +
						"   Stringfield7," +
						"   Sq_5," +
						"   Sq_6," +
						"   Sq_7," +
						"   registerstatus," +
						"   stashtime," +
						"   audittime," +
						"   Createdby," +
						"   Createddate)" +
						"  Select '" + Customer_Guid + "'," +
						"         '" + customerid + "'," +
						"         '" + customerid + "'," +
						"         '" + customername + "'," +
						"         '***'," +
						"         '" + phone_enc + "'," +
						"         '" + register + "'," +
						"         '" + register_id + "'," +
						"         " + registertime + "," +
						"         '" + inviterhstno + "'," +
						"         '" + invitername + "'," +
						"         '" + invitertype + "'," +
						"         '" + registerstatus + "'," +
						"         " + stashtime + "," +
						"         " + audittime + "," +
						"         'SELITE'," +
						"         Now()" +
						"    From dual";

				// 插入Objective表
				custTaskDealSQL[1] = "Insert Into Objective" +
						"  (Objective_Guid," +
						"   Objectivetype_Id," +
						"   Handleby_Id," +
						"   Handlegroup_Id," +
						"   Priority_Id," +
						"   Expireddate," +
						"   Customer_Guid," +
						"   Objectivestatus," +
						"   Iscontact," +
						"   Trytimes," +
						"   Successfulcontacttimes," +
						"   Createdby," +
						"   Createddate," +
						"   Obstatus," +
						"   Failure_Attempt," +
						"   Contact_Customer_Guid," +
						"   Passflag," +
						"   Lastassigndate," +
						"   Failstatus," +
						"   Successstatus," +
						"   Owner," +
						"   Workorderframe_Id," +
						"   Category," +
						"   Forecastdate," +
						"   Workorderid," +
						"   Workordertype1," +
						"   Workordertype2," +
						"   Workordertype3," +
						"   Workordertype4," +
						"   Objectivesubstatus," +
						"   Map_Id," +
						"   Curstep_Id_Map," +
						"   Max_Attempt," +
						"   Nocontacttry," +
						"   Allocation_Pool," +
						"   Appointment,distributionnumber)" +
						"Values" +
						"  ('" + Objective_Guid + "'," +
						"   'RE0TX1'," +
						"   null," +
						"   null," +
						"   'NORMAL'," +
						"   Date_Add(Now(), Interval 1 Day)," +
						"   '" + Customer_Guid + "'," +
						"   'OPEN'," +
						"   0," +
						"   0," +
						"   0," +
						"   'SELITE'," +
						"   Now()," +
						"   'OPEN'," +
						"   999," +
						"   ''," +
						"   0," +
						"   Null," +
						"   '0'," +
						"   '0'," +
						"   ''," +
						"   'MY48ZX'," +
						"   'CASE'," +
						"   '2021-04-25 17:59:35'," +
						"   Concat('HS', Date_Format(Now(), '%Y%m%d%H'), '-', Lpad(Floor(Rand() * 10000), 4, '0'))," +
						"   'QL800E'," +
						"   'O7JIUV'," +
						"   ''," +
						"   ''," +
						"   ''," +
						"   'MY48ZX'," +
						"   'ONA0KD'," +
						"   0," +
						"   0," +
						"   0," +
						"   0,0)";

				// 插入EliteTask表
				custTaskDealSQL[2] = "Insert Into Elitetask" +
						"  (Elitetask_Guid," +
						"   Objective_Guid," +
						"   Objectivetype_Id," +
						"   Expectstarttime," +
						"   Expectendtime," +
						"   Obstatus," +
						"   Recordstatus," +
						"   Attempt," +
						"   Max_Attempt," +
						"   Handleby_Id," +
						"   Handlegroup_Id," +
						"   Createdby," +
						"   Createddate," +
						"   Failure_Attempt," +
						"   Comments," +
						"   Customer_Guid," +
						"   Localtrycount," +
						"   Lastassigndate," +
						"   Workorderframe_Id," +
						"   Curstepstatus," +
						"   Curstep_Id," +
						"   Stepforecastdate," +
						"   Curstep_Id_Map," +
						"   Map_Id," +
						"   Objectivesubstatus," +
						"   Elitetaskstatus," +
						"   Obflag,Maintaskstep_Id_Map)" +
						"Values" +
						"  ('" + EliteTask_Guid + "'," +
						"   '" + Objective_Guid + "'," +
						"   'RE0TX1'," +
						"   Now()," +
						"   Date_Add(Now(), Interval 3 Day)," +
						"   'OPEN'," +
						"   0," +
						"   1," +
						"   999," +
						"   null," +
						"   null," +
						"   'SELITE'," +
						"   Now()," +
						"   999," +
						"   ''," +
						"   '" + Customer_Guid + "'," +
						"   0," +
						"   Now()," +
						"   ''," +
						"   'OPEN'," +
						"   'ONA0KD'," +
						"   Now()," +
						"   'ONA0KD'," +
						"   'MY48ZX'," +
						"   ''," +
						"   'OPEN'," +
						"   1,'ONA0KD')";

				log.debug("客户入库处理SQL："+custTaskDealSQL);
				int[] batchSQLResult = eliteBean.updateBatch(custTaskDealSQL, "dataSource");
				log.debug("客户入库处理SQL返回结果："+batchSQLResult.toString());

				reJson = "{\"result\":\"1\",\"message\":"+ result +"}";
			}else if(code == "20003"){
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"20003\",\"message\":\"查询客户注册后信息获取失败(" + msg + ")\"}";
			}else {
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"-1\",\"message\":\"查询客户注册后信息获取失败(" + msg + ")\"}";
			}

		} catch (JSONException e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			reJson = "{\"result\":\"-1\",\"message\":\"查询客户注册后信息获取接口异常\"}";
		}

		return reJson;
	}

	//更新customer  有objective任务
	public static String getcust1(EliteBean eliteBean , String injson, String Customer_Guid) {

		long startTime = System.currentTimeMillis();
		log.debug("处理开始时间:" + startTime);

		long endTime = System.currentTimeMillis();

		String reJson = null;
		try {

			String doURL = getProperty.get("HSTURL");
			doURL = doURL+"/ae/query-register-info";
			log.debug("doURL:" + doURL);

			Map<String, String> headMap = new HashMap<String, String>();
			headMap.put("Content-Type", "application/x-www-form-urlencoded");
			def getResult = Util.doHttpPostUseHead(doURL, injson, "UTF-8", 10000, 0, headMap);
			log.debug("getResult:" + getResult);

			//解析SSO返回信息
			JSONObject jsonObject = new JSONObject(getResult);
			String code = GetJV(jsonObject, "code");
			String result = GetJV(jsonObject, "result");

			JSONObject dataObject;
			log.debug("code:" + code);
			if(code == "00000") {
				dataObject = new JSONObject(result);
				String registerstatus = GetJV(dataObject, "registerstatus");//1已开户 2（注册） 3（暂存） 4（审核中）
				String customerid = GetJV(dataObject, "customerid");//华盛号
				String customername = GetJV(dataObject, "customername");//姓名
				String phone = GetJV(dataObject, "phone");//手机号
				String register = GetJV(dataObject, "register");//注册渠道
				String register_id = GetJV(dataObject, "register_id");//注册渠道ID
				String registertime = GetJV(dataObject, "registertime");//注册时间
				String stashtime = GetJV(dataObject, "stashtime");//暂存时间
				String audittime = GetJV(dataObject, "audittime");//审核时间
				String invitertype = GetJV(dataObject, "invitertype");//邀请类型
				String inviterhstno = GetJV(dataObject, "inviterhstno");//邀请人华盛号
				String invitername = GetJV(dataObject, "invitername");//邀请人姓名

				//手机号脱敏
				String phone_enc =  DecryptUtil.encrypt(phone) ;

				if(registertime!=""){
					registertime="'"+registertime+"'";
				}else{
					registertime=null;
				}
				if(stashtime!=""){
					stashtime="'"+stashtime+"'";
				}else{
					stashtime=null;
				}
				if(audittime!=""){
					audittime="'"+audittime+"'";
				}else{
					audittime=null;
				}

				String[] custTaskDealSQL = new String[1];

				custTaskDealSQL[0] = "update Customer set" +
						"   Customer_Id= case when '" + customerid + "' is null or '" + customerid + "' ='' then Customer_Id else '" + customerid + "' end," +
						"   Customername=case when '" + customername + "' is null or '" + customername + "' ='' then Customername else '" + customername + "' end ," +
						"   Mobile='***'," +
						"   Mobile_enc=case when '" + phone_enc + "' is null or '" + phone_enc + "' ='' then Mobile_enc else '" + phone_enc + "' end ," +
						"   Stringfield13=case when '" + register + "' is null or '" + register + "' ='' then Stringfield13 else '" + register + "' end," +
						"   sq_9=case when '" + register_id + "' is null or '" + register_id + "' ='' then sq_9 else '" + register_id + "' end," +
						"   Stringfield7=case when " + registertime + " is null or " + registertime + " ='' then Stringfield7 else " + registertime + " end," +
						"   Sq_5=case when '" + inviterhstno + "' is null or '" + inviterhstno + "' ='' then Sq_5 else '" + inviterhstno + "' end," +
						"   Sq_6=case when '" + invitername + "' is null or '" + invitername + "' ='' then Sq_6 else '" + invitername + "' end," +
						"   Sq_7=case when '" + invitertype + "' is null or '" + invitertype + "' ='' then Sq_7 else '" + invitertype + "' end," +
						"   registerstatus =case when '" + registerstatus + "'=1 then 1 else '" + registerstatus + "'end," +
						"   stashtime=case when " + stashtime + " is null or " + stashtime + " ='' then stashtime else " + stashtime + " end," +
						"   audittime=case when " + audittime + " is null or " + audittime + " ='' then audittime else " + audittime + " end," +
						"   MODIFIEDBY='SELITE'," +
						"   MODIFIEDDATE=Now() where Customer_Guid ='" + Customer_Guid + "'";

				log.debug("客户入库处理SQL："+custTaskDealSQL);
				int[] batchSQLResult = eliteBean.updateBatch(custTaskDealSQL, "dataSource");
				log.debug("客户入库处理SQL返回结果："+batchSQLResult.toString());

				reJson = "{\"result\":\"1\",\"message\":\"当前客户已存在，对应已更新customer!\"}";
			}else if(code == "20003"){
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"20003\",\"message\":\"当前客户已存在，查询客户注册后信息获取失败(" + msg + ")\"}";
			}else {
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"-1\",\"message\":\"当前客户已存在，查询客户注册后信息获取失败(" + msg + ")\"}";
			}

		} catch (JSONException e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			reJson = "{\"result\":\"-1\",\"message\":\"查询客户注册后信息获取接口异常\"}";
		}

		return reJson;
	}

	//更新customer  无objective任务
	public static String getcust2(EliteBean eliteBean , String injson, String Customer_Guid) {

		long startTime = System.currentTimeMillis();
		log.debug("处理开始时间:" + startTime);

		long endTime = System.currentTimeMillis();

		String reJson = null;
		try {

			String doURL = getProperty.get("HSTURL");
			doURL = doURL+"/ae/query-register-info";
			log.debug("doURL:" + doURL);

			Map<String, String> headMap = new HashMap<String, String>();
			headMap.put("Content-Type", "application/x-www-form-urlencoded");
			def getResult = Util.doHttpPostUseHead(doURL, injson, "UTF-8", 10000, 0, headMap);
			log.debug("getResult:" + getResult);

			//解析SSO返回信息
			JSONObject jsonObject = new JSONObject(getResult);
			String code = GetJV(jsonObject, "code");
			String result = GetJV(jsonObject, "result");

			JSONObject dataObject;
			log.debug("code:" + code);
			if(code == "00000") {
				dataObject = new JSONObject(result);
				String registerstatus = GetJV(dataObject, "registerstatus");//1已开户 2（注册） 3（暂存） 4（审核中）
				String customerid = GetJV(dataObject, "customerid");//华盛号
				String customername = GetJV(dataObject, "customername");//姓名
				String phone = GetJV(dataObject, "phone");//手机号
				String register = GetJV(dataObject, "register");//注册渠道
				String register_id = GetJV(dataObject, "register_id");//注册渠道ID
				String registertime = GetJV(dataObject, "registertime");//注册时间
				String stashtime = GetJV(dataObject, "stashtime");//暂存时间
				String audittime = GetJV(dataObject, "audittime");//审核时间
				String invitertype = GetJV(dataObject, "invitertype");//邀请类型
				String inviterhstno = GetJV(dataObject, "inviterhstno");//邀请人华盛号
				String invitername = GetJV(dataObject, "invitername");//邀请人姓名

				if(registertime!=""){
					registertime="'"+registertime+"'";
				}else{
					registertime=null;
				}
				if(stashtime!=""){
					stashtime="'"+stashtime+"'";
				}else{
					stashtime=null;
				}
				if(audittime!=""){
					audittime="'"+audittime+"'";
				}else{
					audittime=null;
				}

				// 生成相关ID
				String Temp_Guid = KHUtil.getRandomString(31).toUpperCase();
				String Objective_Guid,EliteTask_Guid;

				Objective_Guid = "OBJE_" + Temp_Guid;
				EliteTask_Guid = "TASK_" + Temp_Guid;

				String[] custTaskDealSQL = new String[3];

				custTaskDealSQL[0] = "update Customer set" +
						"   Customer_Id= case when '" + customerid + "' is null or '" + customerid + "' ='' then Customer_Id else '" + customerid + "' end," +
						"   Customername=case when '" + customername + "' is null or '" + customername + "' ='' then Customername else '" + customername + "' end ," +
						"   Mobile='***'," +
						"   Stringfield13=case when '" + register + "' is null or '" + register + "' ='' then Stringfield13 else '" + register + "' end," +
						"   sq_9=case when '" + register_id + "' is null or '" + register_id + "' ='' then sq_9 else '" + register_id + "' end," +
						"   Stringfield7=case when " + registertime + " is null or " + registertime + " ='' then Stringfield7 else " + registertime + " end," +
						"   Sq_5=case when '" + inviterhstno + "' is null or '" + inviterhstno + "' ='' then Sq_5 else '" + inviterhstno + "' end," +
						"   Sq_6=case when '" + invitername + "' is null or '" + invitername + "' ='' then Sq_6 else '" + invitername + "' end," +
						"   Sq_7=case when '" + invitertype + "' is null or '" + invitertype + "' ='' then Sq_7 else '" + invitertype + "' end," +
						"   registerstatus =case when '" + registerstatus + "'=1 then registerstatus else '" + registerstatus + "'end," +
						"   stashtime=case when " + stashtime + " is null or " + stashtime + " ='' then stashtime else " + stashtime + " end," +
						"   audittime=case when " + audittime + " is null or " + audittime + " ='' then audittime else " + audittime + " end," +
						"   MODIFIEDBY='SELITE'," +
						"   MODIFIEDDATE=Now() where Customer_Guid ='" + Customer_Guid + "'";

				// 插入Objective表
				custTaskDealSQL[1] = "Insert Into Objective" +
						"  (Objective_Guid," +
						"   Objectivetype_Id," +
						"   Handleby_Id," +
						"   Handlegroup_Id," +
						"   Priority_Id," +
						"   Expireddate," +
						"   Customer_Guid," +
						"   Objectivestatus," +
						"   Iscontact," +
						"   Trytimes," +
						"   Successfulcontacttimes," +
						"   Createdby," +
						"   Createddate," +
						"   Obstatus," +
						"   Failure_Attempt," +
						"   Contact_Customer_Guid," +
						"   Passflag," +
						"   Lastassigndate," +
						"   Failstatus," +
						"   Successstatus," +
						"   Owner," +
						"   Workorderframe_Id," +
						"   Category," +
						"   Forecastdate," +
						"   Workorderid," +
						"   Workordertype1," +
						"   Workordertype2," +
						"   Workordertype3," +
						"   Workordertype4," +
						"   Objectivesubstatus," +
						"   Map_Id," +
						"   Curstep_Id_Map," +
						"   Max_Attempt," +
						"   Nocontacttry," +
						"   Allocation_Pool," +
						"   Appointment,distributionnumber)" +
						"Values" +
						"  ('" + Objective_Guid + "'," +
						"   'RE0TX1'," +
						"   null," +
						"   null," +
						"   'NORMAL'," +
						"   Date_Add(Now(), Interval 1 Day)," +
						"   '" + Customer_Guid + "'," +
						"   'OPEN'," +
						"   0," +
						"   0," +
						"   0," +
						"   'SELITE'," +
						"   Now()," +
						"   'OPEN'," +
						"   999," +
						"   ''," +
						"   0," +
						"   Null," +
						"   '0'," +
						"   '0'," +
						"   ''," +
						"   'MY48ZX'," +
						"   'CASE'," +
						"   '2021-04-25 17:59:35'," +
						"   Concat('HS', Date_Format(Now(), '%Y%m%d%H'), '-', Lpad(Floor(Rand() * 10000), 4, '0'))," +
						"   'QL800E'," +
						"   'O7JIUV'," +
						"   ''," +
						"   ''," +
						"   ''," +
						"   'MY48ZX'," +
						"   'ONA0KD'," +
						"   0," +
						"   0," +
						"   0," +
						"   0,0)";

				// 插入EliteTask表
				custTaskDealSQL[2] = "Insert Into Elitetask" +
						"  (Elitetask_Guid," +
						"   Objective_Guid," +
						"   Objectivetype_Id," +
						"   Expectstarttime," +
						"   Expectendtime," +
						"   Obstatus," +
						"   Recordstatus," +
						"   Attempt," +
						"   Max_Attempt," +
						"   Handleby_Id," +
						"   Handlegroup_Id," +
						"   Createdby," +
						"   Createddate," +
						"   Failure_Attempt," +
						"   Comments," +
						"   Customer_Guid," +
						"   Localtrycount," +
						"   Lastassigndate," +
						"   Workorderframe_Id," +
						"   Curstepstatus," +
						"   Curstep_Id," +
						"   Stepforecastdate," +
						"   Curstep_Id_Map," +
						"   Map_Id," +
						"   Objectivesubstatus," +
						"   Elitetaskstatus," +
						"   Obflag,Maintaskstep_Id_Map)" +
						"Values" +
						"  ('" + EliteTask_Guid + "'," +
						"   '" + Objective_Guid + "'," +
						"   'RE0TX1'," +
						"   Now()," +
						"   Date_Add(Now(), Interval 3 Day)," +
						"   'OPEN'," +
						"   0," +
						"   1," +
						"   999," +
						"   null," +
						"   null," +
						"   'SELITE'," +
						"   Now()," +
						"   999," +
						"   ''," +
						"   '" + Customer_Guid + "'," +
						"   0," +
						"   Now()," +
						"   ''," +
						"   'OPEN'," +
						"   'ONA0KD'," +
						"   Now()," +
						"   'ONA0KD'," +
						"   'MY48ZX'," +
						"   ''," +
						"   'OPEN'," +
						"   1,'ONA0KD')";

				log.debug("客户入库处理SQL："+custTaskDealSQL);
				int[] batchSQLResult = eliteBean.updateBatch(custTaskDealSQL, "dataSource");
				log.debug("客户入库处理SQL返回结果："+batchSQLResult.toString());

				reJson = "{\"result\":\"1\",\"message\":\"当前客户已存在，对应已更新customer+objective+elitetask！\"}";
			}else if(code == "20003"){
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"20003\",\"message\":\"当前客户已存在，查询客户注册后信息获取失败(" + msg + ")\"}";
			}else {
				String msg = GetJV(jsonObject, "msg");
				reJson = "{\"result\":\"-1\",\"message\":\"当前客户已存在，查询客户注册后信息获取失败(" + msg + ")\"}";
			}

		} catch (JSONException e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			reJson = "{\"result\":\"-1\",\"message\":\"查询客户注册后信息获取接口异常\"}";
		}

		return reJson;
	}

	// 解析Json值
	public static String GetJV(JSONObject inJson, String getKey) {
		String Rev_Value = null;
		try {
			Rev_Value = inJson.getString(getKey);
		} catch (Exception e) {
			try {
				Rev_Value = String.valueOf(inJson.getInt(getKey));
			} catch (Exception e1) {
				try {
					Rev_Value = String.valueOf(inJson.getJSONArray(getKey));
				} catch (Exception e2) {
					try {
						Rev_Value = String.valueOf(inJson.getJSONObject(getKey));
					} catch (Exception e3) {
						Rev_Value = "";
					}
				}
			}
		} finally {
			if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
				Rev_Value = "";
			} else {
			}
		}
		log.debug("解析-k=" + getKey + " v=" + Rev_Value);
		return Rev_Value;
	}


	// 非空校验isNull
	public static boolean isNull(String value) {

		boolean reFlag = true;
		if (value == "" || value.length() <= 0) {
			reFlag = true;
		} else {
			reFlag = false;
		}
		log.debug(reFlag);
		return reFlag;
	}

	// 非空校验isNullMSG
	public static String isNullMSG(String key, String value) {

		String reResult = "";
		if (value == "" || value.length() <= 0) {
			reResult = key + "必填字段;";
		}
		return reResult;
	}

}
